package org.eenie.cartoonist.ui.book;

import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.eenie.cartoonist.R;
import org.eenie.cartoonist.base.BaseActivity;
import org.eenie.cartoonist.injector.ComponentJudge;
import org.eenie.cartoonist.model.BookDetailEntity;
import org.eenie.cartoonist.utils.ImgUtil;

import javax.inject.Inject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class BookDetailActivity extends BaseActivity implements BookContract.View, ComponentJudge<BookComponent> {


    @Bind(R.id.bookCover)
    ImageView bookCover;
    @Bind(R.id.txtPrice)
    TextView txtPrice;
    @Bind(R.id.txtSun)
    TextView txtSun;
    @Bind(R.id.txtPublish)
    TextView txtPublish;
    @Bind(R.id.txtName)
    TextView txtName;
    @Bind(R.id.btnLoad)
    Button btnLoad;
    @Bind(R.id.activity_book_detail)
    RelativeLayout activityBookDetail;

    @Inject
    BookPresenter mPresenter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_book_detail);
        ButterKnife.bind(this);
        DaggerBookComponent.builder()
                .bookPresenterModule(new BookPresenterModule())
                .build()
                .inject(this);
        mPresenter.attachView(this);
    }

    @Override
    public void displayBookDetail(BookDetailEntity entity) {
        ImgUtil.bind(bookCover, entity.getImage());
        txtName.setText(entity.getSubtitle());
        txtPrice.setText(this.getString(R.string.book_price, entity.getPrice()));
        txtPublish.setText(entity.getPublisher());
        txtSun.setText(entity.getSummary());
    }


    @OnClick(R.id.btnLoad)
    public void fetBookDetail() {
        mPresenter.fetBookDetail("6548683");
    }


    @Override
    public BookComponent fetComponent() {
        return null;
    }
}
